package com.cinc.ebc.sd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cinc.ebc.sd.entity.SdContractDetail;
import com.cinc.ebc.sd.mapper.SdContractDetailMapper;
import com.cinc.ebc.sd.service.ISdContractDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 销售合同明细
 * @Author: jeecg-boot
 * @Date:   2022-08-01
 * @Version: V1.0
 */
@Service
public class SdContractDetailServiceImpl extends ServiceImpl<SdContractDetailMapper, SdContractDetail> implements ISdContractDetailService {

	@Autowired
	private SdContractDetailMapper sdContractDetailMapper;

	@Override
	public List<SdContractDetail> selectByMainId(String mainId) {
		return sdContractDetailMapper.selectByMainId(mainId);
	}

	@Override
	public Map<String, Object> queryPriceStatFp() {
		return sdContractDetailMapper.selectPriceStatFp();
	}

	@Override
	public List<Map<String, Object>> queryMonthPriceStatFp() {
		List<Map<String, Object>> curMonthPriceList = baseMapper.selectMonthPriceThisYear();
		Map<String, Object> curMonthMap = new HashMap<>();
		curMonthPriceList.forEach(curMonthPrice -> curMonthMap.put(curMonthPrice.get("month").toString(), curMonthPrice.get("money")));
		List<Map<String, Object>> monthPriceList = new ArrayList<>();
		for(int i =1; i<= 12; i++){
			Map<String, Object> monthPrice = new HashMap<>();
			monthPrice.put("x", i+"月");
			if(curMonthMap != null && curMonthMap.containsKey(i+"")){
				monthPrice.put("y", curMonthMap.get(i+""));
			}else{
				monthPrice.put("y", 0);
			}
			monthPriceList.add(monthPrice);
		}

		return monthPriceList;
	}
}
